<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('报告名称')" prop="reportName">
            <el-input v-model="form.reportName" :placeholder="$t('报告名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('聚焦行业')" prop="focusIndustry">
            <dict-select
              v-model="form.focusIndustry"
              dictionary="deal_industry_focus"
              :placeholder="$t('聚焦行业')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('报告时间')" prop="reportTime">
            <el-date-picker
              v-model="form.reportTime"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('报告时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('报告人')" prop="reportUser">
            <UserSelect v-model="form.reportUser" :placeholder="$t('报告人')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="industry_report" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="industry:report" />
    </div>
  </div>
</template>

<script>
    import { saveIndustryReport, getIndustryReport } from '@/api/fund/industry/report/industryReport'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                  reportName: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  reportTime: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  reportUser: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }],
                  focusIndustry: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }]
                },
                // 遮罩层
                loading: false,
                // 操作按钮默认不展示
                buttonShow: true,
                // 是否隐藏其它按钮
                otherBtnHide: false
            }
        },
        created() {
            this.getDicts('deal_industry_focus').then(response => {
                this.focusIndustryOptions = response.data
            })
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getIndustryReport(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    }).catch(() => {
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    reportName: undefined,
                    reportTime: new Date(),
                    focusIndustry: undefined,
                    reportUser: this.$store.state.user.userId,
                    remark: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                    this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
          /** 提交按钮 */
          submitForm() {
            this.$refs['form'].validate(valid => {
              if (valid) {
                this.loading = true
                saveIndustryReport(this.form).then(response => {
                  if (response.code === 200) {
                    this.msgSuccess(this.$t('保存成功'))
                    this.closeForm()
                  } else {
                    this.msgError(response.msg)
                  }
                  this.loading = false
                })
              } else {
                this.locationError(document)
              }
            }).catch(() => {
              this.loading = false
            })
          }

        }

    }
</script>
